import os, sys, json
from example.sql_parser import generate_config, MODULE_NAME
from graph.relation_graph import EntityRelationGraph
from graph.mock_graph import MockGenerator
from graph_mock_generator import generator_sql, generator_liquibase

# 将运行目录作为环境变量
currentPath = os.path.dirname(__file__)
sys.path.append(currentPath)

def generate_complex_table():
    path = generate_config()
    with open(path, "r", encoding="utf-8") as f:
        config_data = json.load(f)  # 直接从文件加载 JSON

    entry_graph = EntityRelationGraph(config_data)
    mock_generator = MockGenerator(entry_graph)
    # mock_generator.print_order()
    mock_data = mock_generator.mock_data()

    sql_items = generator_sql(config_data["tables"], mock_data, "mysql")
    generator_liquibase(sql_items, MODULE_NAME, comment=MODULE_NAME, context="fj")


if __name__ == "__main__":
    generate_complex_table()
